package com.itheima.service.mongo.impl;

import com.itheima.domain.db.FocusUser;
import com.itheima.service.mongo.FocusUserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * @author zsk
 * @create 2022-03-23-18:10
 */
@DubboService
public class FocusUserServiceImpl implements FocusUserService {

    @Autowired
    private MongoTemplate mongoTemplate;

    //关注用户
    @Override
    public void saveFocusUser(FocusUser focusUser) {
        //保存关注用户
        mongoTemplate.save(focusUser);
    }

    //取消关注
    @Override
    public void removeFocusUser(Long userId, Long focusUserId) {
        //构建条件
        Query query = new Query(Criteria.where("userId").is(userId)
        .and("focusUserId").is(focusUserId));

        //删除
        mongoTemplate.remove(query,FocusUser.class);

    }
}
